home *** CD-ROM | disk | FTP | other *** search
- /* TMyApp.cpp
- *
- * Create my application
- */
-
- #include <XWindow.h>
- #include <XStdControls.h>
- #include <XPrinter.h>
- #include "MyApp.h"
-
- /************************************************************************/
- /* */
- /* Construction/Destruction */
- /* */
- /************************************************************************/
-
- /* TMyApp::TMyApp
- *
- * Bring me up. Initialize the standard controls library
- */
-
- TMyApp::TMyApp()
- {
- XGInitStandardControls();
- }
-
- /* TMyApp::~TMyApp
- *
- * Shut me down. Shut down standard control library
- */
-
- TMyApp::~TMyApp()
- {
- XGKillStandardControls();
- }
-
- /************************************************************************/
- /* */
- /* Message Dispatch */
- /* */
- /************************************************************************/
-
- /* TMyApp::ReceiveDispatch
- *
- * When a menu item is selected, a message is dispached. I receive
- * all those not handled elsewhere
- */
-
- long TMyApp::ReceiveDispatch(long msg, long arg, void *parg)
- {
- XGSMenuStatusRecord *s;
-
- switch (msg) {
- case KEventDoMenuCommand:
- /*
- * Do the 'open' and 'page setup'
- */
-
- switch (arg) {
- case 100: /* Open */
- DoOpenWindow();
- return 1;
- case 101: /* Page Setup */
- GPrinter.PageSetup();
- return 1;
- }
- break;
-
- case KEventGetMenuStatus:
- /*
- * Enable 'open' and 'page setup'
- */
-
- switch (arg) {
- case 100:
- case 101:
- s = (XGSMenuStatusRecord *)parg;
- s->enable = true;
- return 1;
- }
- break;
- }
-
- /*
- * Default: pass up
- */
-
- return XGAppMultiWindow::ReceiveDispatch(msg,arg,parg);
- }
-
- /* TMyApp::CreateView
- *
- * Create my custom views
- */
-
- XGView *TMyApp::CreateView(long viewID, XGView *parent, XGArgStream &s)
- {
- switch (viewID) {
- case 'TEXT':
- return new TTextView(parent,s);
- default:
- return NULL;
- }
- }
-
- /************************************************************************/
- /* */
- /* Window management */
- /* */
- /************************************************************************/
-
- /* TMyApp::DoOpenWindow
- *
- * Open a window
- */
-
- void TMyApp::DoOpenWindow(void)
- {
- XGWindow *w;
- TTextView *t;
- FILE *f;
-
- /*
- * Open the file
- */
-
- #if OPT_MACOS == 1
- StandardFileReply reply;
- SFTypeList list = { 'TEXT' };
- short refNum;
- long dirID;
-
- StandardGetFile(NULL,1,list,&reply);
- if (!reply.sfGood) return;
- HGetVol(NULL,&refNum,&dirID);
- HSetVol(NULL,reply.sfFile.vRefNum,reply.sfFile.parID);
- f = fopen(p2cstr(reply.sfFile.name),"r");
- HSetVol(NULL,refNum,dirID);
- #endif
-
- #if OPT_WINOS == 1
- OPENFILENAME ofn;
- char filter[256];
- char *c;
- char title[256];
- char file[256];
-
- memset(&ofn,0,sizeof(ofn));
- ofn.lStructSize = sizeof(ofn);
- ofn.hwndOwner = _GMainWindow;
- ofn.hInstance = _GInstance;
-
- strcpy(filter,"Text Files(*.TXT)|*.txt|");
- for (c = filter; *c != 0; c++) if (*c == '|') *c = 0;
- ofn.lpstrFilter = filter;
- file[0] = 0;
- title[0] = 0;
-
- ofn.nFilterIndex = 1;
- ofn.lpstrFile = file;
- ofn.nMaxFile = sizeof(file);
- ofn.lpstrFileTitle = title;
- ofn.nMaxFileTitle = sizeof(title);
- ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
-
- if (!GetOpenFileName(&ofn)) return;
-
- f = fopen(ofn.lpstrFile,"r");
- #endif
-
- /*
- * Create the text window
- */
-
- w = XGWindow::Create(128); // text window
-
- /*
- * Name the window
- */
-
- #if OPT_MACOS == 1
- w->SetWindowName((char *)reply.sfFile.name);
- #endif
- #if OPT_WINOS == 1
- w->SetWindowName(ofn.lpstrFileTitle);
- #endif
-
- /*
- * Open the text file
- */
-
- t = (TTextView *)(w->FindViewByID(101));
- if (t) {
- t->ShowFile(f);
- }
- }
-